home *** CD-ROM | disk | FTP | other *** search
/ Netware Super Library / Netware Super Library.iso / pgm_tool / lu62 / debug / help.c < prev    next >
C/C++ Source or Header  |  1995-07-03  |  5KB  |  160 lines

  1. /*
  2.  *  CopyRight 1995. Nicholas Poljakov all rights reserved.
  3.  */
  4. /*********** help-type a help-file  **********************/
  5. /*    pid_page-page ident. pointer                       */
  6. /*********************************************************/
  7.  
  8. #include <stdio.h>
  9. #include <ctype.h>
  10. #include <string.h>
  11. #include <dos.h>
  12. #include <io.h>
  13. #include <fcntl.h>
  14. #include <malloc.h>
  15. #include <stdlib.h>
  16. #define PU  73   /* Page Up      */
  17. #define PD  81   /* Page Down    */
  18. #define ESC '\033'
  19. #define TPG    50
  20. #define MAX_FRAME 31
  21.  
  22. extern int fp_help;
  23. extern struct index
  24.     {  long reset;
  25.        char ind_str[4];
  26.        short lentxt;
  27.     } index[TPG];
  28. extern struct menu_frame {
  29.     int startx, endx, starty, endy;
  30.     unsigned char *p;
  31.     char **menu;
  32.     char *keys;
  33.     int border;
  34.     int count;
  35.     unsigned char attrib;
  36.     int active;
  37.     int curx, cury;
  38.     char *header;
  39.     unsigned char shd;
  40.     } frame[MAX_FRAME];
  41.  
  42.  
  43.     help(pid_page)
  44.             unsigned long *pid_page;
  45.               {
  46.         unsigned long i;
  47.         unsigned n;
  48.                 unsigned ch;
  49.         unsigned char str[81];
  50.         char msg[40];
  51.         char num[5];
  52.                 long pos;
  53.                 char *p_page[50];
  54.                 int x,y,k;
  55.         char *p_str = " PgDown for more or  Esc for exit";
  56.  
  57.         memcpy(num, pid_page, 4);
  58.         num[4] = 0x00;
  59.                 k=0;
  60.                 while ((memcmp(pid_page,index[k].ind_str,4))&&
  61.                                          (k < 50))
  62.                         k++;
  63.                 if (k == 50) {
  64.                    quit(1);
  65.                    return 0;
  66.                 }
  67.  
  68.                 i=index[k].lentxt;
  69.                 if ((p_page[0] = malloc (i)) == NULL) {
  70.                    quit(2);
  71.                    return 0;
  72.                 }
  73.                 if ( (pos = lseek(fp_help,index[k].reset ,SEEK_SET)) ==  -1L ) {
  74.                    quit( 4);
  75.                    return 0;
  76.                 }
  77.                 if ( (read(fp_help,p_page[0],i)) < 0) {
  78.                    quit (5);
  79.                    return 0;
  80.                 }
  81.                 window(25);
  82.                 str[0] = 195;
  83.                 memset(&str[1], 196, 78);
  84.                 str[79] = 180;
  85.         str[80] = 0x00;
  86.         strcpy(msg, "Help page  ");
  87.         strcat(msg,  num);
  88.         write_string(1,2,msg, frame[25].attrib | 0x0f);
  89.         write_string(2,0,str, frame[25].attrib);
  90.                 write_string(22,0,str, frame[25].attrib);
  91.                 n=0;
  92.  
  93.             WRC:
  94.                 x=5;
  95.                 y=1;
  96.                 while (( x < 21 )  && (n < i)) {
  97.                      write_string(x,y,p_page[0]+n, frame[25].attrib & 0xf0);
  98.                      n+=strlen(p_page[0] + n) + 1;
  99.                      x++;
  100.                 }
  101.                 if (n < i) {
  102.                      k++;
  103.                      p_page[k] = p_page[0] + n;
  104.                      write_string(23,(80-strlen(p_str))/2,p_str, frame[25].attrib & 0xf0);
  105.                 }
  106.                 else {
  107.              write_string(23,30,"Press ESC to exit...",frame[25].attrib | 0x0f);
  108.                      }
  109.      GC:
  110.                ch=getch();
  111.                if ( ch == ESC) {
  112.                   deactivate (25);
  113.                   return 0;
  114.                }
  115.                if (ch == 0) {
  116.                     if (getch() == PU ) {
  117.                         if (k > 1)  {
  118.                              k-=2;
  119.                              n=p_page[k]-p_page[0];
  120.                              goto WRC;
  121.                         }
  122.                     }
  123.                     if (getch() == PD) {
  124.                         if ( n < i)
  125.                              goto WRC;
  126.                     }
  127.                }
  128.                goto GC;
  129.  }
  130. /*****************************************************************/
  131.     quit(i)
  132.       int i;
  133.        {
  134.           unsigned ch;
  135.  
  136.               window(14);
  137.               window_xy(14, 2, 0);
  138.           switch (i)
  139.                 {
  140.                     case 1:
  141.                        { window_puts(14, " Help page not found");
  142.                          break;
  143.                        }
  144.                     case 3:
  145.                        { window_puts(14, " Error open for help");
  146.                          break;
  147.                        }
  148.                     case 2:
  149.                     case 4:
  150.                     case 5:
  151.                        { window_puts(14, "Error read help file");
  152.                          break;
  153.                        }
  154.  
  155.                     while ((ch = getch()) != ESC) ;
  156.                     deactivate(14);
  157.                   }
  158.         }
  159.    /*********************** THE END ***************************/
  160.